#pragma once
#include "Client.h"

class CClientManager
{
public:
    CClientManager(void);
    ~CClientManager(void);

#ifdef USE_CLIENT_BUFFER
    void CreateClient(SOCKADDR_IN& addr, 
        UINT cbAddrLen, SOCKET hSocketClient, LPPER_IO_OPERATION_DATA lpPerIOData, UINT& uiOffset, POSITION posClientSprite);
    void RemoveClient(SOCKET hSocketClient);
    BOOL GetClientOffset(SOCKET hSocketClient, UINT &uiOffset);
    BOOL SetClientOffset(SOCKET hSocketClient, const UINT &uiOffset);
#else
    void CreateClient(SOCKADDR_IN& addr, UINT cbAddrLen, UINT& uiOffset);
    void RemoveClient(SOCKADDR_IN& addr, UINT cbAddrLen);
    BOOL GetClientOffset(SOCKADDR_IN& addr, UINT cbAddrLen, UINT &uiOffset);
    BOOL SetClientOffset(SOCKADDR_IN &addr, UINT cbAddrLen, const UINT &uiOffset);
#endif
    void RemoveAllClients();
    void RemoveClientsTimeout();
    BOOL GetClientSprite(SOCKET hSocketClient, POSITION* pPosClientSprite);

private:
#ifdef USE_CLIENT_BUFFER
    CMap<SOCKET, SOCKET&, CClient, CClient&> m_mapClients;
#else
    CMap<SOCKADDR_IN, SOCKADDR_IN&, CClient, CClient&> m_mapClients;
#endif
    CCriticalSection m_critialSection;
};